﻿using System;
using System.Configuration;
using App_Code;
using OrkutAPILibrary;
using OrkutAPILibrary.Enums;

public partial class SelfInfo : System.Web.UI.Page
{
    /// <summary>
    /// Gets or sets the _orkut library.
    /// </summary>
    /// <value>The _orkut library.</value>
    private OrkutLibrary _orkutLibrary
    {
        get { return (OrkutLibrary)Application["OrkutLibrary"]; }
        set { Application["OrkutLibrary"] = value; }
    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (_orkutLibrary == null)
            {
                _orkutLibrary = OrkutLibrary.Initialize(ApplicationEnvironment.Web, new TokenManager
                                                                                        {
                                                                                            ConsumerKey =
                                                                                                ConfigurationManager.
                                                                                                AppSettings[
                                                                                                    "CONSUMER_KEY"],
                                                                                            ConsumerSecret =
                                                                                                ConfigurationManager.
                                                                                                AppSettings[
                                                                                                    "CONSUMER_SECRET"
                                                                                                ]
                                                                                        },
                                                        ConfigurationManager.AppSettings["TOKEN_KEY"]);
            }

            if (_orkutLibrary.IsAuthorizationNeeded)
            {
                _orkutLibrary.AuthorizeWebRequest();
            }

            var orkutPerson = _orkutLibrary.GetSelfProfile();

            lblInfo.Text = "<h4>This is YOUR Profile.</h4> <h4>Your name is " + orkutPerson.DisplayName +
                           "</h4> <h4>You are a " + orkutPerson.Gender +
                           "</h4> <h4>living in " + orkutPerson.CurrentLocation.Region +
                           "</h4> <h4>which is in a great country called " + orkutPerson.CurrentLocation.Country +
                           "</h4> <h4>Something more about you - " + orkutPerson.AboutMe + "</h4>";
        }
    }
}